﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ingebet;
using Ingebet.Model;
using Ingebet.Model.Domain;

namespace Ingebet.Web
{
    public partial class Register : BasePage
    {
        protected void Page_Load(object sender , EventArgs e)
        {
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            var link = Master.FindControl("btnDeconnexion") as LinkButton;
            link.Visible = false;
        }

        private void LkClick(object sender , EventArgs e)
        {
            Response.Redirect("/Web/Login.aspx");
        }

        protected void ValiderEmail(object source , ServerValidateEventArgs args)
        {
            var ut = Global.Container.Resolve<UtilisateurModel>().GetByEmail(this.Email.Text);
            if (ut == null)
            {
                args.IsValid = true;
                return;
            }
            args.IsValid = false;
        }

        protected void CreateUserButton_Click(object sender , EventArgs e)
        {
            Utilisateur util = new Utilisateur();
            util.Civilite = this.ddlCivilite.SelectedValue;
            util.Nom = this.UserName.Text;
            util.Prenom = this.UserPrenom.Text;
            util.Email = this.Email.Text;
            util.Password = this.Password.Text;
            util.Solde = 1000;
            Global.Container.Resolve<UtilisateurModel>().Insert(util);
            Session["UtilId"] = util.Id;
            Response.Redirect(string.Format("/Web/AccueilCompte.aspx"));
        }
    }
}